<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>积分兑换</title>
		<link rel="stylesheet" type="text/css" href="../css/aui.css" />
		<link rel="stylesheet" type="text/css" href="../css/style.css" />
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
	</head>

	<body>
		<div class="myui-jifen-box">

			<div id="zfb_img" style="text-align:center;">
				<img id="skm_img" src="../image/skm.png" alt="收款码" style="width:100px;display:inline-block;">
			</div>

			<form enctype="multipart/form-data">
				<div class="" style="position:relative;">
					<input type="file" name="" value="" style="position:absolute;width:100%;height:100%;top:0px;left:0px;opacity:0;" onchange="changImg(event,'skm_img')">
					<div style="font-size:0.7rem;display: inline-block;padding: 8px 22px;color: white;border: 1px solid;border-radius: 3px;background-color:#03a9f4;" tapmode onclick="dhxj()">上传支付宝收款码</div>
				</div>
			</form>

			<div class="myui-jifen-1">
				<h2 id="sign"></h2>当前吾爱金币
			</div>
			<div id="bili2" class="myui-jifen-2" style="padding-top:2rem;">

			</div>
			<div class="auixj aui-bar aui-bar-btn" style="width:80%;" type="count" id="demo2">
				<div class="aui-bar-btn-item aui-font-size-20">
					<i class="aui-iconfont aui-icon-minus"></i>
				</div>
				<div class="auixj-quy aui-bar-btn-item">
					<input type="number" style="height: 1.8rem;font-size: 20px;" class="auinbr aui-input aui-text-center" id="count" value="10" min="10">
				</div>
				<div class="aui-bar-btn-item aui-font-size-20">
					<i class="aui-iconfont aui-icon-plus"></i>
				</div>
			</div>
			<div class="myui-jifen-bt">
				<div style="font-size:0.7rem;display: inline-block;padding: 8px 22px;color: white;border: 1px solid;border-radius: 3px;background-color:#89AE00;" tapmode onclick="openWin('share_win')">获取金币</div>
				<div style="font-size:0.7rem;display: inline-block;padding: 8px 22px;color: white;border: 1px solid;border-radius: 3px;background-color:#03a9f4;" tapmode onclick="dhxj()">兑换现金</div>
			</div>
			<div class="myui-jifen-bt">
			</div>

		</div>

	</body>
	<script type="text/javascript" src="../script/jquery-3.1.1.min.js"></script>
	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/auitab.js"></script>

	<script>
		function changImg(e, imgid) {
			var formData = new FormData($('form')[0]);
			$.ajax({
				url: 'http://up.imgapi.com/',
				type: 'POST',
				xhr: function() {
					myXhr = $.ajaxSettings.xhr();
					if(myXhr.upload) {
						myXhr.upload.addEventListener('progress', progressHandlingFunction, false);
					}
					return myXhr;
				},
				beforeSend: function() {
					$('progress').show();
				},
				success: function(data) {
					console.log(data);
					//$('#res').html(JSON.stringify(data));
					alert("上传成功，linkurl:" + data.linkurl);
					//window.location.reload();
				},
				error: function(data) {
					console.log(data);
				},
				data: formData,
				cache: false,
				contentType: false,
				processData: false
			});

			/*
			    for (var i = 0; i < e.target.files.length; i++) {
			        var file = e.target.files.item(i);
			        if (!(/^image\/.*$/i.test(file.type))) {
			            continue; //不是图片 就跳出这一次循环
			        }
			        //实例化FileReader API
			        var freader = new FileReader();
			        freader.readAsDataURL(file);
			        freader.onload = function(e) {
			            //$("#"+imgid).attr("src",e.target.result);
			            var Imgsrc=e.target.result;
			            api.showProgress({
			               title: '收款码上传中...',
			               modal: false
			           });

			           /*
			          var values= {
			            uid: localStorage.getItem('user_id'),
			            zfb: Imgsrc
			          }
			                     alert( JSON.stringify( values ) );
			           api.ajax({
			             url: 'https://test.msapp.co/login/login/zfbcz.html',
			             method: 'post',
			             data: {
			               "values":values
			             }
			           }, function(ret, err) {
			             if(ret) {
			                			  alert( JSON.stringify( ret ) );
			               if(ret.code == 1) {
			                 api.hideProgress();
			                 var img=$api.byId(imgid);
			                 img.src=e.target.result;
			                 alert('上传成功');
			               } else if(ret.code == 0) {
			                 api.hideProgress();
			                 alert('修改失败');
			               } else {
			                 api.hideProgress();
			                 alert('网络错误！11');
			               }
			             }
			           });*
			        }
			    }*/
		}
		$(':button').click(function() {
			var formData = new FormData($('form')[0]);
			$.ajax({
				url: 'http://up.imgapi.com/',
				type: 'POST',
				xhr: function() {
					myXhr = $.ajaxSettings.xhr();
					if(myXhr.upload) {
						myXhr.upload.addEventListener('progress', progressHandlingFunction, false);
					}
					return myXhr;
				},
				beforeSend: function() {
					$('progress').show();
				},
				success: function(data) {
					console.log(data);
					$('#res').html(JSON.stringify(data));
					alert("上传成功，linkurl:" + data.linkurl);
					//window.location.reload();
				},
				error: function(data) {
					console.log(data);
				},
				data: formData,
				cache: false,
				contentType: false,
				processData: false
			});
		});

		function progressHandlingFunction(e) {
			if(e.lengthComputable) {
				$('progress').attr({
					value: e.loaded,
					max: e.total
				});
			}
		}
	</script>

	<script type="text/javascript">
		var api_url = localStorage.getItem('api_url');

		apiready = function() {
			api.parseTapmode();
			api.showProgress({
				title: '正在刷新',
				text: '请稍等...',
				modal: false
			});
			api.ajax({
				url: 'https://test.msapp.co/login/login/sign.html',
				method: 'get',
				data: {
					values: {
						uid: localStorage.getItem('user_id')
					}
				}
			}, function(ret, err) {
				if(ret) {
					var sign = $api.byId('sign');
					sign.innerHTML = ret.msg['share'];
					localStorage.setItem('user_jinb', ret.msg['share']);
				} else {
					api.hideProgress();
					alert('网络错误11');
				}
			});

			api.ajax({
				url: 'https://test.msapp.co/login/login/share.html',
				method: 'get',
				data: {
					values: {
						uid: localStorage.getItem('user_id')
					}
				}
			}, function(ret, err) {
				if(ret) {
					//var bili = $api.byId('bili');

					//bili.innerHTML = '100吾爱金币可以兑换1天会员资格！';
					bili2.innerHTML = '100吾爱金币可以兑换1元现金!';
					api.hideProgress();
				} else {
					api.hideProgress();
					alert('获取失败');

				}
			});
		}

		function fasong() {
			var ajax = new XMLHttpRequest();
			ajax.open('post', 'https://test.msapp.co/appx/cesaj.php');
			ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

			var bianl1 = document.querySelector('#sign');
			var bianl2 = document.querySelector('#count').value;
			var bianl3 = Number(bianl1.innerText) - (Number(bianl2) * 100); //兑换吾爱金币/积分比率!!!!
			var bianyu = Number(bianl3);
			if(bianyu <= 0) {
				alert('吾爱金币不足，无法兑换')
				return;
			}
			var shuji = Number(bianl2);
			sign.innerHTML = bianyu;
			localStorage.setItem('user_jinb', bianyu);
			var userid = localStorage.getItem('user_id');
			var student = new Object();
			student.id = userid;
			student.age = shuji;
			var json = JSON.stringify(student);
			ajax.send('json=' + json);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4 && ajax.status == 200) {
					console.log(ajax.responseText);
					alert('兑换成功！恭喜获得' + ajax.responseText + '天VIP')
				}
			};
		}

		function dhxj() {
			var ajax = new XMLHttpRequest();
			ajax.open('post', 'https://test.msapp.co/appx/dhxj.php');
			ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

			var bianl1 = document.querySelector('#sign');
			var bianl2 = document.querySelector('#count').value;
			var bianl3 = Number(bianl1.innerText) - (Number(bianl2) * 100); //兑换吾爱金币/积分比率!!!!
			var bianyu = Number(bianl3);
			if(bianyu <= 0) {
				alert('吾爱金币不足，无法兑换')
				return;
			}
			/*if(bianl2 < 20) {
				alert('金额满50元，方可提现，或者您可以用金币兑换您的吾爱演示VIP时长哦！继续努力邀请好友吧！')
				return;
			}*/
			var shuji = Number(bianl2);
			sign.innerHTML = bianyu;
			localStorage.setItem('user_jinb', bianyu);
			var userid = localStorage.getItem('user_id');
			var student = new Object();
			student.id = userid;
			student.age = shuji;
			var json = JSON.stringify(student);
			//alert(json)
			ajax.send('json=' + json);
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 4 && ajax.status == 200) {
					alert(ajax.status);
					alert(ajax.readyState);
					alert('申请提现成功！恭喜获得' + ajax.responseText + '元现金')
				}else{
					alert('网络异常请稍后再试！')
				}
			};
		}
		/*
		  function exchange00(){
		    var share = $api.val($api.byId('count'));

		    api.ajax({
		        url: api_url+'/login/login/exchange.html',
		        method: 'get',
		        data: {
		            values: {
		                uid: localStorage.getItem('user_id'),
		                share:share*jifenbi
		            }
		        }
		    },function(ret, err){
		        if (ret) {
		            if (ret.code == 0) {
		              alert( ret.msg );
		            }else {
		              getTime();
		              alert( '成功兑换'+share+'天会员' );
		            }

		        } else {
		          api.hideProgress();
		            alert( '网络错误22' );
		        }
		    });
		  }
		*/

		//重新获取到期时间
		function getTime() {
			api.ajax({
				url: 'https://test.msapp.co/login/login/veifys.html',
				method: 'get',
				data: {
					values: {
						username: localStorage.getItem('user_name'),
						passwd: localStorage.getItem('password'),
						imei: api.deviceId
					}
				}
			}, function(ret, err) {
				if(ret) {
					if(ret.code == 0) {
						api.hideProgress();
						alert('不明错误 请重新登录');
					} else if(ret.code == 1) {
						localStorage.setItem('user_time', ret.msg['time']);
						api.sendEvent({
							name: 'newLoingdata',
							extra: {}
						});
					}
				} else {
					api.hideProgress();
					alert('网络错误！33');
				}
			});
		}

		var bar = document.querySelectorAll(".aui-bar-btn");
		if(bar) {
			for(var i = 0; i < bar.length; i++) {
				var d = bar[i];
				var tab = new auiTab({
					element: bar[i],
					repeatClick: true
				}, function(ret) {
					//alert( JSON.stringify( ret ) );
					if(ret.dom.parentNode.getAttribute("type") && ret.dom.parentNode.getAttribute("type") == "count") {
						var count = parseInt(document.getElementById("count").value);
						//if(ret.index==2)return;
						if(ret.index == 1) {
							if(document.getElementById("count").value <= 1) {
								return;
							}
							document.getElementById("count").value = count - 1;
						}
						if(ret.index == 3) {
							document.getElementById("count").value = count + 1;
						}
					}
				});

			}
		}

		function openWin(name) {
			var delay = 0;
			if(api.systemType != 'ios') {
				delay = 300;
			}
			api.openWin({
				name: '' + name + '',
				url: '' + name + '.html',
				bounces: false,
				delay: delay,
				slidBackEnabled: true,
				vScrollBarEnabled: false
			});
		}
	</script>

	<script>
		function niccz() {
			var btnncxg = $api.val($api.byId('btnnc'));
			var btnnc = $api.byId('btnnc');
			var niccs = localStorage.getItem('nicxgcs');
			if(niccs == 1) {
				alert('今天您已修改,请3天之后再操作');
				return;
			}
			if(btnncxg == '修 改') {
				hui('#nictxt').hide();
				hui('#nickname').show();
				btnnc.value = '保 存';
				return;
			}

			var nicknamex = $api.val($api.byId('nickname'));
			if(nicknamex == '') {
				api.alert({
					title: '亲爱的!~',
					msg: '昵称不能为空哦',
				});
				return;
			}
			api.ajax({
				url: 'https://test.msapp.co/login/login/niccz.html',
				method: 'get',
				data: {
					values: {
						uid: localStorage.getItem('user_id'),
						nickname: nicknamex
					}
				}
			}, function(ret, err) {
				if(ret) {
					if(ret.code == 1) {
						var btnnc = $api.byId('btnnc');
						var nictxt = $api.byId('nictxt');
						hui('#nickname').hide();
						btnnc.value = '修 改';
						hui('#nictxt').show();
						nictxt.innerHTML = nicknamex;
						localStorage.setItem('nicxgcs', '1');
						localStorage.setItem('user_nickname', nicknamex);

					} else if(ret.code == 0) {
						api.hideProgress();
						alert('修改失败');
					} else {
						api.hideProgress();
						alert('网络错误！11');
					}
				}
			});

		}

		function zfbcz() {
			var btnzfbxg = $api.val($api.byId('btnzfb'));
			var btnzfb = $api.byId('btnzfb');
			var zfbcs = localStorage.getItem('zfbxgcs');
			if(zfbcs == 1) {
				alert('今天您已修改,请3天之后再操作');
				return;
			}
			if(btnzfbxg == '修 改') {
				hui('#zfbtxt').hide();
				hui('#zfb').show();
				btnzfb.value = '保 存';
				return;
			}
			var zfbx = $api.val($api.byId('zfb'));
			if(zfbx == '') {
				api.alert({
					title: '亲爱的!~',
					msg: '昵称不能为空哦',
				});
				return;
			}
			api.ajax({
				url: 'https://test.msapp.co/login/login/zfbcz.html',
				method: 'get',
				data: {
					values: {
						uid: localStorage.getItem('user_id'),
						zfb: zfbx
					}
				}
			}, function(ret, err) {
				if(ret) {
					if(ret.code == 1) {
						var zfbtxt = $api.byId('zfbtxt');
						hui('#zfb').hide();
						btnzfb.value = '修 改';
						hui('#zfbtxt').show();
						zfbtxt.innerHTML = zfbx;
						localStorage.setItem('zfbxgcs', '1');
						localStorage.setItem("user_zfb", zfbx);

					} else if(ret.code == 0) {
						api.hideProgress();
						alert('修改失败');
					} else {
						api.hideProgress();
						alert('网络错误！11');
					}
				}
			});
		}

		function wxcz() {
			var btnweixinxg = $api.val($api.byId('btnweixin'));
			var btnweixin = $api.byId('btnweixin');
			var weixincs = localStorage.getItem('weixinxgcs');
			if(weixincs == 1) {
				alert('今天您已修改,请3天之后再操作');
				return;
			}
			if(btnweixinxg == '修 改') {
				hui('#weixintxt').hide();
				hui('#weixin').show();
				btnweixin.value = '保 存';
				return;
			}
			var weixinx = $api.val($api.byId('weixin'));
			if(weixinx == '') {
				api.alert({
					title: '亲爱的!~',
					msg: '微信不能为空哦',
				});
				return;
			}
			api.ajax({
				url: 'https://test.msapp.co/login/login/weixincz.html',
				method: 'get',
				data: {
					values: {
						uid: localStorage.getItem('user_id'),
						weichat: weixinx
					}
				}
			}, function(ret, err) {
				if(ret) {
					if(ret.code == 1) {
						var weixintxt = $api.byId('weixintxt');
						hui('#weixin').hide();
						btnweixin.value = '修 改';
						hui('#weixintxt').show();
						weixintxt.innerHTML = weixinx;
						localStorage.setItem('weixinxgcs', '1');
						localStorage.setItem('user_weixin', weixinx);

					} else if(ret.code == 0) {
						api.hideProgress();
						alert('修改失败');
					} else {
						api.hideProgress();
						alert('网络错误！11');
					}
				}
			});

		}
	</script>

</html>